package com.fram.controller.api;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fram.bean.sys.ResponseMsg;
import com.fram.common.canstant.ErrCode;
import com.fram.common.exception.ProException;
import com.fram.common.util.PublicMethod;
import com.fram.common.util.apiversion.ApiVersion;
import com.fram.entity.Checkversion;
import com.fram.service.api.v1.CheckversionSerivce;

@RestController
@RequestMapping("/api/{version}/app/version")
public class CheckversionAppController {
	
	private static Logger LOG = LoggerFactory.getLogger(CheckversionAppController.class);
	
	@Autowired
	private CheckversionSerivce checkversionSerivce;
	
	@ApiVersion(1.0)
	@RequestMapping("list")
	private ResponseMsg list(@RequestBody Checkversion request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			msg.setData(checkversionSerivce.list(request));
		} catch (ProException e) {
			LOG.error("-最新版本展示出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-最新版本展示异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
	
	@ApiVersion(1.0)
	@RequestMapping("details")
	private ResponseMsg details(Long id) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			msg.setData(checkversionSerivce.details(id));
		} catch (ProException e) {
			LOG.error("-版本详情出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-版本详情异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
}
